package top.leetcode;

/**
 * @Desc
 * @Author houruiyang
 * @Date 2022/12/23
 **/
public class _035 {

    public static void main(String[] args) {
        int[] a = new int[]{1,3,5,6};
        System.out.println(searchInsert(a, 5));
    }

    public static int searchInsert(int[] nums, int target) {
        int  length= nums.length;
        int left = 0;
        int right = length - 1;
        int ans = length;
        while (left <= right) {
            int mid = left + ((right - left) /2);
            if (target <= nums[mid]) {
                ans = mid;
                right = mid - 1;
            } else {
                left = mid + 1;
            }
        }
        return ans;
    }
}
